<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ include file="../common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <title>交易统计</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon"/>
    <!-- 当前页面样式 -->
    <link rel="stylesheet" href="<s:url value="/css/common.css"/>"/>
    <!-- 当前页面样式 END -->
    <script type="text/javascript" src="<c:url value="/js/jquery-1.3.2.js" />"></script>
	<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
	<script type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
    <script type="text/javascript">
		
function checkSubmit(){
	if(dateCheck()){
		$("#queryUserForm").attr("action","<%=basePath%>/estrnlog/queryEstrnStastics.ct");
		$("#queryUserForm").submit();
		$("#queryBtnId").attr("disabled","true");
	}else{
		
		return false;
	}
	
}

function summarrySubmit(){
	if(dateCheck()){
		$("#queryUserForm").attr("action","<%=basePath%>/estrnlog/summaryEstrnStastics.ct");
		$("#queryUserForm").submit();
		$("#summaryBtnId").attr("disabled","true");
	}else{
		
		return false;
	}
}

function exportSubmit(){
	if(dateCheck()){
		$("#queryUserForm").attr("action","<%=basePath%>/estrnlog/exportEstrnStastics.ct");
		$("#queryUserForm").submit();
	}else{
		
		return false;
	}
}

function dateCheck(){
	var minDate = $.trim($("#minDate").val());
	var maxDate = $.trim($("#maxDate").val());
	
	
	if(!minDate || !maxDate){
		alert("请选择交易时间范围");
		return false;
	}
	
	if(minDate > maxDate){
		alert("起始时间大于结束时间");
		return false;
	}
	
	var date1=str2date(minDate);
	var date2=str2date(maxDate);
	
	if(date1.getMonth()!=date2.getMonth()){
	    alert("选择的时间范围不在同一个月内！");
		return false;
	}
	
	var date1=str2date(minDate);
	var date2=str2date(maxDate);    //结束时间
	var days = date2.getDate()-date1.getDate();
	if(days>2){
		alert("最多只能查询三天之内的交易统计");
		return;
	}
	
	var yesterday = $("#yesterday").val();
	var today = $("#today").val();
	
	
	if(maxDate < yesterday){
		$("#dateFlag").val("1");
		return true;
	}
	
	if(minDate >= yesterday && maxDate <= today){
		$("#dateFlag").val("2");
		return true;
	}
	alert("时间校验未通过，请查看上方提示");
	return false;
}

function   str2date(str){   
	var   d=null;   
	var   reg=/^(\d{4})(\d{2})(\d{2})$/  ;
	if(arr=str.match(reg)) d=new Date(Number(arr[1]),Number(arr[2])-1,Number(arr[3])) ; 
	return   d;   
}

</script>
</head>
<body>
<s:form id="queryUserForm" action="" method="post" theme="simple">
<input id="yesterday" value="${yesterday }" type="hidden"/>
<input id="today" value="${today }" type="hidden"/>
<input id="dateFlag" type="hidden" name="searchCondition.dateFlag"/>
<table class="tb">
    <tbody>
        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h2">POS收单运营管理平台</div><font color="red">提示：如当天日期为20170223，则交易统计支持的查询及导出时间范围为20170221及以前或者20170222到20170223</font></td>
        </tr>

        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h3">交易统计</div></td>
        </tr>

        <tr class="tb-line">
        	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
                <div class="tb-h4">交易日期范围：</div>
            </td>
            <td class="tb-td">
                <label class="tb-input-mini"><s:textfield id="minDate"  name="searchCondition.minDate" 
                onfocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});" 
                /></label>-<label class="tb-input-mini"><s:textfield id="maxDate"  name="searchCondition.maxDate" 
                onfocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});" 
                /></label><code class="asterisk">*</code>
            </td>
            <td width="12%" style="min-width: 150px" align="right" class="tb-td">
	               <div class="tb-h4">区域：</div>
	        </td>
	         <td class="tb-td">
	               <label class="tb-input-normal"><s:select cssClass="queryWidth" name="searchCondition.areaId" id="areaId"
							list="#request.areaCodeList" listKey="id" listValue="name" headerKey="-1" headerValue="--请选择--" /></label>
	         </td>
         </tr>

        <tr class="tb-line">
            <td class="tb-td line-submit" align="right" colspan="4">
                <label class="tb-input-submit">
                    <input id="queryBtnId" type="button" value="查   询" onclick="return checkSubmit();" />
                </label>
                <label class="tb-input-submit">
                    <input id="summaryBtnId" type="button" value="汇   总" onclick="return summarrySubmit();" />
                </label>
                <label class="tb-input-submit">
                    <input id="exportBtnId" type="button" value="导出交易统计详情" onclick="return exportSubmit();" />
                </label>
            </td>
        </tr>
        <s:if test="#request.tftList != null && #request.tftList.size>0">
					<tr class="tb-line">
						<td class="tb-td paging"  align="left" colspan="4"> <page:pageCount
								max_pages="11" totalPage="${requestScope.totalPage}"
								currentPage="${requestScope.currentPage}"
								action="${rootPath}/estrnlog/queryEstrnStastics.ct?currentPage=" />

						</td>
					</tr>
	</s:if>
    </tbody>
    
</table>

<div class="big-tb">
	<s:if test="#request.esList != null && #request.esList.size>0">
    <table class="tb" style="width: 100%;">
        <thead>
            <tr class="tb-line">
                <th class="tb-th" colspan="13">交易统计列表</th>
            </tr>
            <tr class="tb-line bg-gray">
                		<th class="tb-th">交易类型</th>
						<th class="tb-th">交易总额(元)</th>
						<th class="tb-th">交易日期</th>
            </tr>
        </thead>
        <tbody>
					<s:iterator value="#request.esList" status="stat" id="tft">
						<tr class="tb-line">
							<td class="tb-td"><s:property value="#tft.maTransCdName" />
							</td>
							<td class="tb-td"><s:property value="#tft.totalMoney" /></td>
							<td class="tb-td"><s:property value="#tft.transDt" /></td>
						</tr>
					</s:iterator>
				</tbody>
    </table>
    </s:if>
    <s:if test="#request.tftList != null && #request.tftList.size>0">
    <table class="tb" style="width: 100%;">
        <thead>
            <tr class="tb-line">
                <th class="tb-th" colspan="13">交易统计详情</th>
            </tr>
            <tr class="tb-line bg-gray">
                		<th class="tb-th">区域</th>
						<th class="tb-th">机构</th>
						<th class="tb-th">交易金额（元）</th>
						<th class="tb-th">交易类型</th>
						<th class="tb-th">交易日期</th>
						<th class="tb-th">卡类型</th>
						<th class="tb-th">接触方式</th>
            </tr>
        </thead>
        <tbody>
					<s:iterator value="#request.tftList" status="stat" id="tft">
						<tr class="tb-line">
							<td class="tb-td"><s:property value="#tft.companyName" />
							</td>
							<td class="tb-td"><s:property value="#tft.oneAgentName" /></td>
							<td class="tb-td"><s:property value="#tft.transAt" /></td>
							<td class="tb-td"><s:property value="#tft.transInf" /></td>
							<td class="tb-td"><s:property value="#tft.transDt" /></td>
							<td class="tb-td"><s:property value="#tft.cardType" /></td>
							<td class="tb-td"><s:property value="#tft.posEntryMdCdName" /></td>
						</tr>
					</s:iterator>
				</tbody>
    </table>
    </s:if>
</div>
</s:form>
</body>
</html>